//
//  NewFoodCollectionViewCell.m
//  FoodFamily
//
//  Created by dlios on 15-6-20.
//  Copyright (c) 2015年 guoBang. All rights reserved.
//

#define HEIGHT1 self.frame.size.height/7 * 2

#import "NewFoodCollectionViewCell.h"

@implementation NewFoodCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame{
    
    
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubCell];
    }

    return self;

}

-(void)creatSubCell{


   
    self.picture_url = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height - self.frame.size.height/7 * 2)];
    self.picture_url.backgroundColor = [UIColor clearColor];
    [self addSubview:self.picture_url];
    [self.picture_url release];

    

    self.user_image = [[UIImageView alloc]initWithFrame:CGRectMake(0,(self.frame.size.height/7) *5 + HEIGHT1/3 *2 - HEIGHT1 /8, HEIGHT1/2,HEIGHT1/2)];
    self.user_image.backgroundColor = [UIColor clearColor];
    self.user_image.layer.masksToBounds = YES;
    self.user_image.layer.cornerRadius =HEIGHT1/4;
    [self addSubview:self.user_image];
    [self.user_image release];
  
    
    
    

     UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0,(self.frame.size.height/7) *5 + HEIGHT1/2,self.frame.size.width, HEIGHT1/2 )];
    button.backgroundColor = [UIColor clearColor];
    [self addSubview:button];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [button release];
    
    
    
    
    

    self.food_name = [[UILabel alloc]initWithFrame:CGRectMake(0,(self.frame.size.height/7) *5,self.frame.size.width, HEIGHT1/3)];
    self.food_name.backgroundColor = [UIColor clearColor];
    self.food_name.font = [UIFont systemFontOfSize:16];
    [self addSubview:self.food_name];
    [self.food_name release];
    
    

    
    self.comment = [[UILabel alloc]initWithFrame:CGRectMake(0, (self.frame.size.height/7) *5 +HEIGHT1/4, self.frame.size.width, HEIGHT1/3)];
    self.comment.font =[UIFont systemFontOfSize:13];
    [self addSubview:self.comment];
    [self.comment release];
    
    

    self.user_name = [[UILabel alloc]initWithFrame:CGRectMake(HEIGHT1/2+HEIGHT1 /20 , (self.frame.size.height/7) *5 + HEIGHT1 /5 *3 - HEIGHT1 /10 , self.frame.size.width -HEIGHT1/2, HEIGHT1/4)];
    self.user_name.font = [UIFont systemFontOfSize:12];
    self.user_name.textColor = [UIColor redColor];
    [self addSubview:self.user_name];
    [self.user_name release];
    

    self.place_name = [[UILabel alloc]initWithFrame:CGRectMake(HEIGHT1/2+HEIGHT1 /10, (self.frame.size.height/7) *5 + HEIGHT1 /5 *3 +HEIGHT1 /8, self.frame.size.width -HEIGHT1/2, HEIGHT1/4)];
    self.place_name.font = [UIFont systemFontOfSize:13];
    [self addSubview:self.place_name];
    [self.place_name release];
    
    

}


-(void)setFoodCM:(FoodCityModle *)foodCM{

    if (_foodCM !=foodCM) {
        [_foodCM release];
        _foodCM = [foodCM retain];
    }

   
    NSURL *url = [NSURL URLWithString:foodCM.picture_url];
 
    [self.picture_url sd_setImageWithURL:url];
    
    NSURL *url1 = [NSURL URLWithString:foodCM.user_image];
    [self.user_image sd_setImageWithURL:url1];
    self.food_name.text = foodCM.food_name;
   
    self.user_name.text = foodCM.user_name;
    NSString *str = [NSString stringWithFormat:@"%@@%@",foodCM.city_name,foodCM.place_name];
    self.place_name.text = str;

    if (![foodCM.comment isEqualToString:@""]) {
         self.comment.text = foodCM.comment;
    }else{
    
    self.comment.text = @"味道不错呦!!!";
    
    }
    
    
    
}



-(void)buttonAction:(UIButton *)button{

    [self.MyDelegate bringButton2:self.foodCM.num];

}

-(void)dealloc{
    [_foodCM release];
    [_picture_url release];
    [_user_image release];
    [_food_name release];
    [_comment release];
    [_user_name release];
   [_place_name release];
   [_button1 release];
    [super dealloc];

}


@end
